﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DBModel
{
    public partial class Skill
    {
        public override string ToString()
        {
            return string.Format("{0}, {1,-20}, {2,-15}, Antal år:{3,2}",
                Skill_Id, SkillName, SkillGrade, SkillYearsOfExperience);
        }

        public string ToHtml()
        {
            return string.Format("{0}<br /> {1}<br /> {2}<br />",
                SkillName, SkillGrade, SkillYearsOfExperience, SkillDescription);
        }
    }

    public static class SkillDB
    {
        public static Skill GetSkillById(int id)
        {
            return DB.Context.Skills
                .Where(s => s.Skill_Id == id)
                .SingleOrDefault(s => !s.IsDeleted);
        }

        public static bool DeleteSkillById(int id)
        {
            Skill skillToDelete = GetSkillById(id);
            if (skillToDelete != null)
            {
                skillToDelete.IsDeleted = true;
                int affectedRows = DB.Context.SaveChanges();
                return (affectedRows > 0);
            }
            return false;
        }
    }
}
